import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

import 'fade_route.dart';

class PhotoViewScreen extends StatelessWidget {
  
  static Future open({required BuildContext context, required String photoUrl}){
    return Navigator.of(context)
        .push(FadeRoute(
        page: PhotoViewScreen(
          imageProvider: NetworkImage(
            photoUrl,
            // headers: const {
            //   "referer": Constants.referer,
            // }
          ),
          heroTag: photoUrl,
        )))
        .then((value) {

    });
  }
  
  const PhotoViewScreen({
    required this.imageProvider,//图片
    this.loadingChild,//加载时的widget
    this.backgroundDecoration,//背景修饰
    this.minScale,//最大缩放倍数
    this.maxScale,//最小缩放倍数
    required this.heroTag,//hero动画tagid
  });
  final ImageProvider imageProvider;
  final Widget? loadingChild;
  final BoxDecoration? backgroundDecoration;
  final dynamic? minScale;
  final dynamic? maxScale;
  final String heroTag;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GestureDetector(
        onTap: (){
          Navigator.of(context).pop();
        },
        child: Container(
          color: Colors.black,
          child: SafeArea(
            child: PhotoView(
              imageProvider: imageProvider,
              loadingBuilder: (BuildContext context,
                  ImageChunkEvent? event,){
                return SizedBox(
                  width: double.infinity,
                    height: double.infinity,
                    child: Center(child: loadingChild??CircularProgressIndicator()));
              },
              backgroundDecoration: backgroundDecoration,
              minScale: minScale,
              maxScale: maxScale,
              heroAttributes: PhotoViewHeroAttributes(tag: heroTag),
              enableRotation: false,
            ),
          ),
        ),
      ),
    );
  }

}
